package Operation;

import JavaBeans.*;

import java.util.Scanner;

public class BorrowOperation implements IOperation{
    @Override
    public void operate(BookList bookList) {
        System.out.println("借阅图书");
        if(bookList.getCurrentCount() == 0){
            System.out.println("当前书架为空！");
            return;
        }
        Scanner in = new Scanner(System.in);
        System.out.println("请输入您要借阅的图书名：");
        String name = in.nextLine();
        for (int i = 0; i < bookList.getCurrentCount(); i++) {
            if(bookList.getBook(i).getName().equals(name)){
                if(bookList.getBook(i).getState() == State.AVAILABLE){
                    bookList.getBook(i).setState(State.TAKEN);
                    System.out.println("借阅成功!");
                }else{
                    System.out.println("此书已被借走！");
                }
                return;
            }
        }
        System.out.println("当前书架无此书");
    }
}
